//
//  UploadPubQuality.m
//  NursingManages
//
//  Created by HuangZhen on 2017/6/9.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "UploadPubQuality.h"
#import <AFNetworking.h>
#import <TMCache.h>
@implementation UploadPubQuality

- (instancetype)init{
    
    NSString *url = AppServiceConfig.GetServiceUrl;
    self.uploadUrl  = [NSString stringWithFormat:@"%@/%@?token=%@",url,@"UploadSaData",[[TMCache sharedCache] objectForKey:@"deviceToken"]];
    self.QCuploadUrl = [NSString stringWithFormat:@"%@/%@?token=%@",url,@"UploadQcData",[[TMCache sharedCache] objectForKey:@"deviceToken"]];
    
    NSLog(@"%@",self.uploadUrl);
    return self;

}

-(void) startUpload:(NSString *)inspect_primary
     inspect_detail:(NSString *)inspect_detail
         inspectNew:(NSString *)inspectNew
             menuid:(NSInteger )menuid
              block: (void(^)(NSDictionary *))callback {

    
    NSMutableDictionary*dic=[[NSMutableDictionary alloc] init];
    [dic setObject:inspect_primary forKey:@"inspect_primary"];
    [dic setObject:inspect_detail forKey:@"inspect_detail"];
    [dic setObject:inspectNew forKey:@"inspect_pointdet"];
    [dic setObject:@(menuid) forKey:@"menuid"];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil] ;//如果报接受类型不一致请替换一致text/html或别的

    [manager POST:self.QCuploadUrl parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"==============%@",responseObject);
        if (callback) {
            callback(responseObject);
        }

        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        if (callback) {
            NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"0",@"flag",@"error",@"msg", nil];
            callback(dict);
        }

    }];
}
-(void) startUpload:(NSString *)inspect_primary block:(void (^)(NSDictionary *))callback
                  {
    
    
    NSMutableDictionary*dic=[[NSMutableDictionary alloc] init];
    [dic setObject:inspect_primary forKey:@"Satisfaction_Detail"];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
                      
    manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil] ;//如果报接受类型不一致请替换一致text/html或别的
    

    [manager POST:self.uploadUrl parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        if (callback) {
            callback(responseObject);
        }
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
        
        if (callback) {
            NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"0",@"flag",@"error",@"msg", nil];
            callback(dict);
        }
        
    }];
}



@end
